//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.sys;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.SysSettingDao;
import com.aidong.model.wills.SysSetting;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"sysSetting"})
public class SysSettingController extends BaseController {
    @Resource
    SysSettingDao sysSettingDao;

    public SysSettingController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("sys/setting/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap(1);
        if(!this.chkNull(name)) {
            cd.like("code", "%" + name + "%");
            cd.like("name", "%" + name + "%");
        }

        this.sysSettingDao.queryPageList(pg, cd, (new OrderSet()).asc("code"));
        ModelAndView mv = new ModelAndView("sys/setting/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        SysSetting set = new SysSetting();
        ModelAndView mv = new ModelAndView("sys/setting/edit");
        mv.addObject("set", set);
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("set") SysSetting set) {
        if(this.chkNull(set.getCode())) {
            return this.getResult(false, "请输入参数Id");
        } else if(this.chkNull(set.getName())) {
            return this.getResult(false, "请输入名称");
        } else if(this.chkNull(set.getValue())) {
            return this.getResult(false, "请输入内容");
        } else {
            set.setCreateUser(this.getLoginUserCode());
            set.setCreateTime(new Date());
            set.setUpdateTime(new Date());
            if(this.sysSettingDao.exists(set.getCode())) {
                return this.getResult(false, "参数已存在");
            } else {
                try {
                    this.sysSettingDao.add(set);
                    this.reloadTypeList("setting");
                    this.addUserLog("新增系统设置", "参数:" + set.getCode() + ",名称:" + set.getName());
                } catch (Exception var3) {
                    this.log.error("add setting", var3);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("code") String code) {
        SysSetting set = (SysSetting)this.sysSettingDao.getById(code);
        if(set == null) {
            return this.showAlert("没有这个记录");
        } else {
            ModelAndView mv = new ModelAndView("sys/setting/edit");
            mv.addObject("set", set);
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("set") SysSetting set) {
        if(this.chkNull(set.getCode())) {
            return this.getResult(false, "请输入参数Id");
        } else if(this.chkNull(set.getName())) {
            return this.getResult(false, "请输入名称");
        } else if(this.chkNull(set.getValue())) {
            return this.getResult(false, "请输入内容");
        } else {
            SysSetting set1 = (SysSetting)this.sysSettingDao.getById(set.getCode());
            if(set1 == null) {
                return this.getResult(false, "没有这个记录");
            } else {
                set1.setName(set.getName());
                set1.setValue(set.getValue());
                set1.setUpdateTime(new Date());

                try {
                    this.sysSettingDao.update(set1);
                    this.reloadTypeList("setting");
                    this.addUserLog("修改系统设置", "参数:" + set1.getCode() + ",名称:" + set1.getName());
                } catch (Exception var4) {
                    this.log.error("edit setting", var4);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("code") String code) {
        SysSetting set = (SysSetting)this.sysSettingDao.getById(code);
        if(set == null) {
            return this.getResult(false, "没有这个记录");
        } else {
            try {
                this.sysSettingDao.delete(set);
                this.reloadTypeList("setting");
                this.addUserLog("删除系统设置", "参数:" + set.getCode() + ",名称:" + set.getName());
            } catch (Exception var4) {
                this.log.error("del setting", var4);
                return this.getResult(false, "删除发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
